﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.UI.DataVisualization.Charting;
using dllLink;

namespace ASPGerant
{
    public partial class cours_utiles : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Nécessaire pour pouvoir utiliser SQL Server CE avec un site ASP
            AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);

            // Create new data series and set it's visual attributes
            
            /*
             * 
             *    EURODOL
             * 
             * **************************/
            
            Series series = new Series("EUR/DOL");
            series.ChartType = SeriesChartType.Line;
            series.BorderWidth = 3;
            series.ShadowOffset = 2;
            Interface adaptater = new Interface();
            adaptater.connectBD();
            AdpDts result = adaptater.selectBD("Cotation, Date", Interface.EURODOL, "1=1 ORDER BY date asc");

            DataTable dt = result.dts.Tables[0];
            foreach (DataRow r in dt.Select())
            {
                String date = r["Date"].ToString();
                String[] test = date.Substring(0, 10).Split('/');
                DateTime dateTimer = new DateTime(Convert.ToInt32(test[2]), Convert.ToInt32(test[1]), Convert.ToInt32(test[0]));

                //DateTime dateTime = new DateTime(Convert.ToInt32(dates[2]), date.Split["/"][1], date.Split["/"][0]);
                series.Points.AddXY(dateTimer, r["Cotation"]);
            }
            // Add series into the chart's series collection
            Chart1.Series.Add(series);
            Chart1.Series["EUR/DOL"]["ShowMarkerLines"] = "True";
            Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.IsEndLabelVisible = true;


            /*
             * 
             *    EURIBOR1M
             * 
             * **************************/

            Series series2 = new Series("EURIBOR1M");
            series2.ChartType = SeriesChartType.Line;
            series2.BorderWidth = 3;
            series2.ShadowOffset = 2;

            result = adaptater.selectBD("Cotation, Date", Interface.EURIBOR1M, "1=1 ORDER BY date asc");

            dt = result.dts.Tables[0];
            foreach (DataRow r in dt.Select())
            {
                String date = r["Date"].ToString();
                String[] test = date.Substring(0, 10).Split('/');
                DateTime dateTimer = new DateTime(Convert.ToInt32(test[2]), Convert.ToInt32(test[1]), Convert.ToInt32(test[0]));

                //DateTime dateTime = new DateTime(Convert.ToInt32(dates[2]), date.Split["/"][1], date.Split["/"][0]);
                series2.Points.AddXY(dateTimer, r["Cotation"]);
            }
            // Add series into the chart's series collection
            Chart2.Series.Add(series2);
            Chart2.Series["EURIBOR1M"]["ShowMarkerLines"] = "True";
            Chart2.ChartAreas["ChartArea1"].AxisX.LabelStyle.IsEndLabelVisible = true;


            /*
             * 
             *    EURIBOR3M
             * 
             * **************************/
            Series series3 = new Series("EURIBOR3M");
            series3.ChartType = SeriesChartType.Line;
            series3.BorderWidth = 3;
            series3.ShadowOffset = 2;

            result = adaptater.selectBD("Cotation, Date", Interface.EURIBOR3M, "1=1 ORDER BY date asc");

            dt = result.dts.Tables[0];
            foreach (DataRow r in dt.Select())
            {
                String date = r["Date"].ToString();
                String[] test = date.Substring(0, 10).Split('/');
                DateTime dateTimer = new DateTime(Convert.ToInt32(test[2]), Convert.ToInt32(test[1]), Convert.ToInt32(test[0]));

                //DateTime dateTime = new DateTime(Convert.ToInt32(dates[2]), date.Split["/"][1], date.Split["/"][0]);
                series3.Points.AddXY(dateTimer, r["Cotation"]);
            }
            // Add series into the chart's series collection
            Chart3.Series.Add(series3);
            Chart3.Series["EURIBOR3M"]["ShowMarkerLines"] = "True";
            Chart3.ChartAreas["ChartArea1"].AxisX.LabelStyle.IsEndLabelVisible = true;



            /*
             * 
             *    EONIA
             * 
             * **************************/



            Series series4 = new Series("EONIA");
            series4.ChartType = SeriesChartType.Line;
            series4.BorderWidth = 3;
            series4.ShadowOffset = 2;

            result = adaptater.selectBD("Cotation, Date", Interface.EONIA, "1=1 ORDER BY date asc");

            dt = result.dts.Tables[0];
            foreach (DataRow r in dt.Select())
            {
                String date = r["Date"].ToString();
                String[] test = date.Substring(0, 10).Split('/');
                DateTime dateTimer = new DateTime(Convert.ToInt32(test[2]), Convert.ToInt32(test[1]), Convert.ToInt32(test[0]));

                //DateTime dateTime = new DateTime(Convert.ToInt32(dates[2]), date.Split["/"][1], date.Split["/"][0]);
                series4.Points.AddXY(dateTimer, r["Cotation"]);
            }
            // Add series into the chart's series collection
            Chart4.Series.Add(series4);
            Chart4.Series["EONIA"]["ShowMarkerLines"] = "True";
            Chart4.ChartAreas["ChartArea1"].AxisX.LabelStyle.IsEndLabelVisible = true;



            /*
             * 
             *    FIRSTFEDFIN
             * 
             * **************************/


            Series series5 = new Series("FIRSTFEDFIN");
            series5.ChartType = SeriesChartType.Line;
            series5.BorderWidth = 3;
            series5.ShadowOffset = 2;

            result = adaptater.selectBD("Cotation, Date", Interface.FIRSTFEDFIN, "1=1 ORDER BY date asc");

            dt = result.dts.Tables[0];
            foreach (DataRow r in dt.Select())
            {
                String date = r["Date"].ToString();
                String[] test = date.Substring(0, 10).Split('/');
                DateTime dateTimer = new DateTime(Convert.ToInt32(test[2]), Convert.ToInt32(test[1]), Convert.ToInt32(test[0]));

                //DateTime dateTime = new DateTime(Convert.ToInt32(dates[2]), date.Split["/"][1], date.Split["/"][0]);
                series5.Points.AddXY(dateTimer, r["Cotation"]);
            }
            // Add series into the chart's series collection
            Chart5.Series.Add(series5);
            Chart5.Series["FIRSTFEDFIN"]["ShowMarkerLines"] = "True";
            Chart5.ChartAreas["ChartArea1"].AxisX.LabelStyle.IsEndLabelVisible = true;



            /*
             * 
             *    LIBORIM
             * 
             * **************************/


            Series series6 = new Series("LIBOR1M");
            series6.ChartType = SeriesChartType.Line;
            series6.BorderWidth = 3;
            series6.ShadowOffset = 2;

            result = adaptater.selectBD("Cotation, Date", Interface.LIBOR1M, "1=1 ORDER BY date asc");

            dt = result.dts.Tables[0];
            foreach (DataRow r in dt.Select())
            {
                String date = r["Date"].ToString();
                String[] test = date.Substring(0, 10).Split('/');
                DateTime dateTimer = new DateTime(Convert.ToInt32(test[2]), Convert.ToInt32(test[1]), Convert.ToInt32(test[0]));

                //DateTime dateTime = new DateTime(Convert.ToInt32(dates[2]), date.Split["/"][1], date.Split["/"][0]);
                series6.Points.AddXY(dateTimer, r["Cotation"]);
            }
            // Add series into the chart's series collection
            Chart6.Series.Add(series6);
            Chart6.Series["LIBOR1M"]["ShowMarkerLines"] = "True";
            Chart6.ChartAreas["ChartArea1"].AxisX.LabelStyle.IsEndLabelVisible = true;


            /*
             * 
             *    LIBOR3M
             * 
             * **************************/



            Series series7 = new Series("LIBOR3M");
            series7.ChartType = SeriesChartType.Line;
            series7.BorderWidth = 3;
            series7.ShadowOffset = 2;

            result = adaptater.selectBD("Cotation, Date", Interface.LIBOR3M, "1=1 ORDER BY date asc");

            dt = result.dts.Tables[0];
            foreach (DataRow r in dt.Select())
            {
                String date = r["Date"].ToString();
                String[] test = date.Substring(0, 10).Split('/');
                DateTime dateTimer = new DateTime(Convert.ToInt32(test[2]), Convert.ToInt32(test[1]), Convert.ToInt32(test[0]));

                //DateTime dateTime = new DateTime(Convert.ToInt32(dates[2]), date.Split["/"][1], date.Split["/"][0]);
                series7.Points.AddXY(dateTimer, r["Cotation"]);
            }
            adaptater.disconnectBD();
            // Add series into the chart's series collection
            Chart7.Series.Add(series7);
            Chart7.Series["LIBOR3M"]["ShowMarkerLines"] = "True";
            Chart7.ChartAreas["ChartArea1"].AxisX.LabelStyle.IsEndLabelVisible = true;
        }

        public String dateMin(String OPCVM)
        {
            Interface adapter = new Interface();
            adapter.connectBD();

            String temp = adapter.dateMinCoteBD(OPCVM);
            adapter.disconnectBD();
            return temp;
        }

        public String dateMax(String OPCVM)
        {
            Interface adapter = new Interface();
            adapter.connectBD();

            String temp = adapter.dateMaxCoteBD(OPCVM);
            adapter.disconnectBD();
            return temp;
        }

        public Double firstCote(String OPCVM)
        {
            Interface adapter = new Interface();
            adapter.connectBD();

            Double temp = adapter.firstCoteBD(OPCVM);
            adapter.disconnectBD();
            return temp;
        }
        public Double lastCote(String OPCVM)
        {
            Interface adapter = new Interface();
            adapter.connectBD();

            Double temp = adapter.lastCoteBD(OPCVM);
            adapter.disconnectBD();
            return temp;
        }

        public Double firstCote100(String OPCVM)
        {
            Interface adapter = new Interface();
            adapter.connectBD();

            Double temp = adapter.firstCoteBD(OPCVM);
            temp = 100 * temp;
            adapter.disconnectBD();
            return temp;
        }
        public Double lastCote100(String OPCVM)
        {
            Interface adapter = new Interface();
            adapter.connectBD();

            Double temp = adapter.lastCoteBD(OPCVM);
            temp = 100 * temp;
            adapter.disconnectBD();
            return temp;
        }
    }
}
